/***
 * @Author:xxx
 * @Date:2020-08-10 14:58:18
 * @LastModifiedBy:xxx
 * @Last Modified time:2020-08-10 14:58:18
 */

import React, { Component } from 'react';
import { Form, Input } from 'antd';
import PropTypes from 'prop-types';
import './modal.css';


class EditOrganForm extends Component {

  
  static propTypes = {
    orgName: PropTypes.string.isRequired,
    orgMobile: PropTypes.string.isRequired,
    orgAddress: PropTypes.string.isRequired,
    orgRemark:  PropTypes.string.isRequired,
    setForm: PropTypes.func.isRequired
  }

  formRef = React.createRef();  // form对象
  
  componentDidMount() {
    this.props.setForm(this.formRef);  // 调用父组件传递的函数，目的是将 参数以实参的形式传递给父组件
    //console.log('form',this.formRef);
  }

  render() {
    const {orgName,orgMobile,orgAddress,orgRemark} = this.props;
    const layout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    };
    return (
      <div>
        <Form 
          {...layout} 
          ref={this.formRef}   //可以通过ref获取数据域
          name="control-ref" 
          initialValues={{
            org_name: orgName,
            org_contact: orgMobile,
            org_address: orgAddress,
            org_remark: orgRemark
          }}
        > 
          <Form.Item 
            name="org_name" 
            label="矿区名称" 
            rules={[{ required: true }]}
          >
            <Input placeholder="请输入矿区名称" disabled/>
          </Form.Item>

          <Form.Item
            name="org_contact"
            label="联系方式"
            rules={[{ required: true, message: '请输入矿区联系方式!' }]}
          >
            <Input placeholder="请输入矿区联系方式"/>
          </Form.Item>

          <Form.Item
            name="org_address"
            label="矿区地址"
            rules={[{ required: true, message: '请输入矿区地址!' }]}
          >
            <Input placeholder="请输入矿区地址"/>
          </Form.Item>

          <Form.Item name="org_remark" label="备注">
            <Input.TextArea />
          </Form.Item>
        </Form>
      </div>
      
    )
  }
}

export default EditOrganForm;